(function() {
  define(function(require, exports, module) {
    var Survey, template;
    template = require('tpl/template');
    return Survey = Backbone.View.extend({
      el: 'body',
      events: {
        'click .btn-question-edit': 'editQuestion',
        'click .btn-question-add': 'addQuestion',
        'click .btn-question-del': 'delQuestion',
        'click .btn-change-to-input': 'changeToInput',
        'click .btn-change-to-select': 'changeToSelect',
        'change .checkbox-multiselect': 'switchMultiSelect'
      },
      renderList: function(data) {
        var html, item, _i, _len, _ref;
        html = '';
        _ref = data.list;
        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
          item = _ref[_i];
          html += template('survey_list', item);
        }
        console.log(html);
        return $('#survey-list tbody').html(html);
      },
      renderSurvey: function(data) {
        var html, q, _i, _len, _ref;
        console.log(data);
        $("#survey-name").val(data.survey.name);
        if (data.survey.description === null || data.survey.description === '') {
          $("#survey-description").html('暂无描述');
        } else {
          $("#survey-description").html(data.survey.description);
        }
        html = '';
        _ref = data.questions;
        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
          q = _ref[_i];
          html += this.renderQuestion(q);
        }
        return $('#survey_questions').html(html);
      },
      renderQuestion: function(data) {
        var html;
        html = '';
        html += template('survey_question_view', data);
        return html;
      },
      renderOption: function(data) {
        var html;
        html = '';
        html += template('survey_option_view', data);
        return html;
      },
      getQuestion: function(e) {
        var data;
        data = {
          id: "",
          name: "",
          answer: null,
          description: null,
          id: "19",
          limit: "",
          maxselect: "0",
          picture: "",
          survey_id: "2",
          tag: "拜访信息",
          type: "1",
          options: []
        };
        return $('.option').each(function(index) {
          return data.options.push(this.getOption($(this)));
        });
      },
      getOption: function(e) {
        var data;
        return data = {
          id: "68",
          isanswer: null,
          name: "有",
          picture: "",
          scroe: "0",
          survey_id: "1",
          survey_question_id: "19"
        };
      },
      addQuestion: function() {
        var data, html, o;
        data = {
          id: "",
          name: "新的题目",
          answer: null,
          description: null,
          id: "19",
          limit: "",
          maxselect: "0",
          picture: "",
          survey_id: "2",
          tag: "拜访信息",
          type: "1",
          options: []
        };
        o = {
          id: "0",
          isanswer: "0",
          name: "选项名称",
          picture: "",
          scroe: "0",
          survey_id: this.getSurveyId(),
          survey_question_id: "0"
        };
        data.options.push(o);
        data.options.push(o);
        html = '';
        html += template('survey_question_edit', data);
        $("#survey_questions").append(html);
        return $('.btn-question-add').hide();
      },
      getSurveyId: function() {
        return $("#survey-id").val();
      },
      changeToSelect: function() {
        $(".btn-change-to-select").hide();
        $(".btn-change-to-input").show();
        $("#option-select").show();
        $("#option-input").hide();
        return $("#question-option-list").show();
      },
      changeToInput: function() {
        $(".btn-change-to-input").hide();
        $(".btn-change-to-select").show();
        $("#option-select").hide();
        $("#option-input").show();
        return $("#question-option-list").hide();
      },
      switchMultiSelect: function() {
        if ($(".checkbox-multiselect:checked").length === 0) {
          return $(".select-limit").show();
        } else {
          return $(".select-limit").hide();
        }
      }
    });
  });

}).call(this);
